/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-08-26 22:24:04
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-08-26 22:44:12
 * @FilePath: /zbt/log system/build.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <string>
#include <memory>

class Computer{
    public:
        Computer(){}
        void setBoard(const std::string &board){
            _board = board;
        }
        void setDisplay(const std::string & display){
            _display = display;
        }
        void ShowParamaters(){
            std::string param = "Computer paramaters:\n";
            param += "\tBoard: " + _board + "\n";
            param += "\tDisplay: " + _display + "\n";
            param += "\tOS: " + _os + "\n";
            std::cout << param << std::endl;
        }
        virtual void setOS() = 0;
    protected:
    std::string _board;
    std::string _display;
    std::string _os;

};

class MacBook: public Computer{
    public:
        void setOS() override{
            _os = "Mac OS x14";
        }
};

class Builder{
    public:
        virtual void buildBoard(const std::string &board) = 0;
        virtual void buildDisplay(const std::string & display) = 0;
        virtual void buildOS() = 0;
        virtual std::shared_ptr<Computer> build() = 0;
};

class MacBookBuilder: public Builder{
    public:
        MacBookBuilder():_computer(new MacBook()){}
        void buildBoard(const std::string & board){
            _computer->setBoard(board);
        }
        void buildDisplay(const std::string & display){
            _computer->setDisplay(display);
        }
        void buildOS(){
            _computer->setOS();
        }

        std::shared_ptr<Computer> build(){
            return _computer;
        }

    private:
        std::shared_ptr<Computer> _computer;
};

class Director{
    public:
        Director(Builder* bulider):_builder(bulider){}
        void construct(const std::string &board, const std::string &display){
            _builder->buildBoard(board);
            _builder->buildDisplay(display);
            _builder->buildOS();
        }
    private:
        std::shared_ptr<Builder> _builder;
};

int main()
{
    Builder* builder = new MacBookBuilder();
    std::unique_ptr<Director> director(new Director(builder));
    director->construct("华硕主板", "三星显示器");
    std::shared_ptr<Computer>computer = builder->build();
    computer->ShowParamaters();
    return 0;
}